package com.sikaryofficial.backend.utils;

import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.crypto.digest.DigestUtil;
import com.sikaryofficial.common.core.exception.ServiceException;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;

/**
 * @author : qinjinyuan
 * @desc : 产品工具类
 * @date : 2023/11/30 11:03
 */
@Slf4j
public class StoreUtil {
    private static final String SPLIT_KEY = "_";
    /**
     * 构建产品md5
     * select md5(CONCAT(t.address_id,'_',t.store_name,'_',t.source_code,'_',t.address) ) from store_t t
     * @param addressId
     * @param storeName
     * @param sourceCode
     * @param addressDetail
     * @return
     */
    public static String buildStoreMd5(Long addressId, String storeName, String sourceCode, String addressDetail) {
        if(Objects.isNull(addressId)){
            addressId = 0L;
        }
        if (CharSequenceUtil.isBlank(storeName) || CharSequenceUtil.isBlank(sourceCode) || CharSequenceUtil.isBlank(addressDetail)) {
            throw new ServiceException("addressId,storeName,sourceCode,addressDetail is empty.");
        }
        return DigestUtil.md5Hex(addressId.toString().concat(SPLIT_KEY).concat(storeName)
                .concat(SPLIT_KEY).concat(sourceCode)
                .concat(SPLIT_KEY).concat(addressDetail));
    }
}
